1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.widget;
9
10 import com.tirsen.angkor.Debug;
11 import com.tirsen.angkor.RenderContext;
12 import com.tirsen.angkor.View;
13 import com.tirsen.angkor.event.Action;
14 import com.tirsen.angkor.event.ActionListener;
15 import com.tirsen.angkor.event.ActionSource;
16 import com.tirsen.angkor.event.ActionSourceHelper;
17 import org.apache.log4j.Category;
18
19 import java.io.IOException;
20
21 /***
22 * @author $Author: tirsen $
23 * @version $Revision: 1.5 $
24 * <BR>
25 * $Id: Link.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $
26 */
27 public class Link extends Container implements ActionSource
28 {
29 private static final Category logger = Category.getInstance(Debug.LOGGER_NAME);
30 private ActionSourceHelper actionSourceHelper = new ActionSourceHelper(this);
31
32 public static Link createActionLink(final Action action)
33 {
34 TextLabel name = new TextLabel();
35 name.setModel(new ReadOnlyValueModel()
36 {
37 public Object getValue()
38 {
39 return action.getValue(Action.NAME);
40 }
41 });
42
43 return createActionLink(action, name);
44 }
45
46 public static Link createActionLink(Action action, View content)
47 {
48 Link link = new Link();
49 link.setAction(action);
50 link.add(content);
51 return link;
52 }
53
54 public Action getAction()
55 {
56 return actionSourceHelper.getAction();
57 }
58
59 public void setAction(Action action)
60 {
61 actionSourceHelper.setAction(action);
62 }
63
64 public void addActionListener(ActionListener listener)
65 {
66 actionSourceHelper.addActionListener(listener);
67 }
68
69 public void removeActionListener(ActionListener listener)
70 {
71 actionSourceHelper.removeActionListener(listener);
72 }
73
74 public void signalActionEvent()
75 {
76 actionSourceHelper.signalActionEvent();
77 }
78
79 public boolean isParsing()
80 {
81 return true;
82 }
83
84 private boolean isEnabled()
85 {
86 return getAction() != null && getAction().isEnabled();
87 }
88
89 public void render(RenderContext context) throws IOException
90 {
91 if (isVisible())
92 {
93 if (!isEnabled())
94 {
95 // render as disabled
96 context.startTag("SPAN id=\"" + uniqueId(context) + "\"");
97 renderChildren(context);
98 context.endTag("SPAN");
99 }
100 else
101 {
102 String url = context.requestURL(uniqueId(context) + "=clicked");
103 context.startTag("A id=\"" + uniqueId(context) + "\" href=\"" + url + "\"");
104 renderChildren(context);
105 context.endTag("A");
106 context.registerParsingComponent(this);
107 }
108 context.println(" ");
109 }
110 }
111
112 public void parse(RenderContext context)
113 {
114 super.parse(context);
115 if (context.getRequestParameter(getId()) != null)
116 {
117 logger.debug("signalling event");
118 actionSourceHelper.signalActionEvent(context);
119 }
120 }
121
122 public static Link createImageStyle(Action action)
123 {
124 Image removeImage = new Image();
125 removeImage.setSourceURL((String) action.getValue(Action.IMAGE_URL));
126 removeImage.setAlt((String) action.getValue(Action.DESCRIPTION));
127 return createActionLink(action, removeImage);
128 }
129 }
This page was automatically generated by Maven